﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

namespace MrPP.SerriedCabinet
{
    public class SearchModel : NetworkBehaviour
    {
        [SyncVar(hook = "changeOpen")]
        public int isOpen = -1;
        public Action<int, int> onOpen{
            get;
            set;
        }
        public void changeOpen(int val) {
            onOpen?.Invoke(isOpen, val);
            isOpen = val;
        }


        [SyncVar(hook = "changeSelected")]
        public int selected = -1;
        public Action<int, int> onSelected
        {
            get;
            set;
        }

        public void changeSelected(int val)
        {
            onSelected?.Invoke(selected, val);
            selected = val;
        }

        [SyncVar(hook = "changeInput")]
        public string input = null;

        public Action<string, string> onInput
        {
            get;
            set;
        }
        public void changeInput(string val)
        {
            onInput?.Invoke(input, val);
            input = val;
        }
        public Action onRefresh
        {
            get;
            set;
        }
        public class DataSyncList : SyncListStruct<CabinetGroup.ItemData>{}
        public DataSyncList datas = new DataSyncList();


        void changed(DataSyncList.Operation op, int itemIndex)
        {
            onRefresh?.Invoke();
        }
        public void Awake() {
            datas.Callback = changed;
        }

    }
}